<?php

namespace Maestros\Model\Dao;

use Zend\Db\Adapter\Adapter;
use Zend\Db\Sql\Sql;
use Maestros\Model\Dao\GenericDAO;

class BloqueDAO extends GenericDAO {

    protected $dbAdapter;

    /**
     * Nombre de la Tabla
     * @var type String
     */
    protected $tabla = 'bloque';
    private static $bloqueDao;

    /**
     * Configura Adaptador de Base de Datos
     * 
     * @param \Zend\Db\Adapter\Adapter $adapter
     */
    private function __construct(Adapter $adapter) {
        $this->dbAdapter = $adapter;
    }

    /**
     * 
     * @param type $adapter
     * @return instancia de BloqueDao
     * Patron singleton
     */
    public static function getInstance($adapter) {
        if (self::$bloqueDao == null) {
            self::$bloqueDao = new BloqueDao($adapter);
        }
        return self::$bloqueDao;
    }

    public function getRegistro($id) {
        return $this->getRegistroGeneral($id, $this->tabla, $this->dbAdapter);
    }

    public function getBloquesSegunDia($dia) {
        $sql = new Sql($this->dbAdapter);
        $select = $sql->select();
        $select->from($this->tabla);
        $select->where("id_dia ='" . $dia . "'");
        $selectString = $sql->getSqlStringForSqlObject($select);
        $adapter = $this->dbAdapter;
        $results = $adapter->query($selectString, $adapter::QUERY_MODE_EXECUTE);
        ;
        return $results;
    }

    public function getBloquesSegunHora($hora) {
        $sql = new Sql($this->dbAdapter);
        $select = $sql->select();
        $select->from($this->tabla);
        $select->where("id_hora ='" . $hora . "'");
        $selectString = $sql->getSqlStringForSqlObject($select);
        $adapter = $this->dbAdapter;
        $results = $adapter->query($selectString, $adapter::QUERY_MODE_EXECUTE);
        ;
        return $results;
    }
}
